<template>
	<!-- 名片夹 -->
	<view class="content bg-white">
		<view class="top_news bg_main text-white font_24 flex justify-center align-center" @click="goPages('/subPages/my/inform/index')" v-if="islogin">
			<u-icon name="bell-fill" color="#ffffff" size="15"></u-icon>
			<view class="ml-1 flex">
				{{ prompt || '系统消息' }}
				<view v-if="prompt" class="ml-1">NEW</view>
			</view>
		</view>
		<view class="p-2"><search-view @search="searchChange" @clear="searchChange('')"></search-view></view>
		<view class="p-2 mt-3" v-if="!islogin">
			<u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" text=" ">
				<template>
					<view class="font-sm c_9">
						登录后可查看消息列表，
						<text class="c_main" @click="goPages('/subPages/login/wx_login')">去登录</text>
					</view>
				</template>
			</u-empty>
		</view>
		<view v-else>
			<view class="c_9 font_22 text-right pr-1" style="transform: translateY(-10rpx);" v-if="cardData.length >= 1">左滑删除</view>
			<indexList v-if="cardData.length >= 1" :list="cardData" :showEmptyDataElement="false" retrieveProperties="name">
				<template #default="{indexList}">
					<index-item v-for="(item, index) in indexList" :item="item" :key="index">
						<template #lineBody>
							<card-list :card-list="item.data" :card-disabled="false" cardcase="cardcase" @cardDel="getInfo"></card-list>
						</template>
					</index-item>
				</template>
			</indexList>
			<view v-else class="p-2 mt-3" style="margin: 100rpx auto;"><u-empty mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png" text="暂无名片信息"></u-empty></view>
		</view>
	</view>
</template>

<script>
import searchView from '@/components/search/search.vue';
import indexItem from './trigger-indexList/trigger-indexList_item/trigger-indexList_item.vue';
import indexList from './trigger-indexList/trigger-indexList/trigger-indexList.vue';
import cardList from '@/components/card_list.vue';
import { messageFriends, businessMessagePush } from '@/api/my/card.js';
export default {
	components: {
		searchView,
		indexList,
		indexItem,
		cardList
	},
	data() {
		return {
			cardData: [],
			scrollTop: 0,
			searchV: '',
			prompt: '',
			islogin: false
		};
	},
	watch: {
		prompt(newV) {
			this.prompt = newV;
		}
	},
	onShow() {
		if (uni.getStorageSync('userInfo').hasLogin) {
			// this.toLogin(); //去登录
			this.islogin = true;
			return;
		}
		this.newPrompt();
		this.messageTips();
	},
	onLoad() {
		this.getInfo();
		// 分享
		// wx.showShareMenu({
		// 	withShareTicket: true,
		// 	menus: ['shareAppMessage', 'shareTimeline']
		// });
	},
	onPullDownRefresh() {
		this.newPrompt();
		this.getInfo();
	},
	methods: {
		searchChange(value) {
			this.searchV = value;
			this.cardData = [];
			this.getInfo();
		},
		getInfo() {
			let msg = {
				kw: this.searchV
			};
			messageFriends(msg)
				.then(res => {
					if (res.code == 0) {
						this.cardData = res.data;
						uni.stopPullDownRefresh();
					} else {
						uni.$u.toast(res.msg);
					}
				})
				.catch(err => {
					console.log('获取名片夹列表失败', err);
				});
		},
		// 提示消息
		newPrompt() {
			businessMessagePush().then(res => {
				if (res.code == 0) {
					this.prompt = res.data.content ? res.data.content : false;
				} else {
					console.log('消息提示获取失败', res.msg);
				}
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.top_news {
	text {
		border: 1px solid #fff;
		border-radius: 20rpx;
		transform: scale(0.5);
		width: 70rpx;
		height: 40rpx;
		font-size: 20rpx;
		text-align: center;
		line-height: 38rpx;
		padding: 3rpx 5rpx;
	}
}
</style>
